package com.yiyi.user.controller;

import com.yiyi.common.annotation.Log;
import com.yiyi.common.core.controller.BaseController;
import com.yiyi.common.core.domain.AjaxResult;
import com.yiyi.common.core.page.TableDataInfo;
import com.yiyi.common.enums.BusinessType;
import com.yiyi.common.utils.SecurityUtils;
import com.yiyi.common.utils.poi.ExcelUtil;
import com.yiyi.user.domain.OrderInfo;
import com.yiyi.user.service.IOrderInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单管理Controller
 *
 * @author yiyi
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/payment/payment")
public class OrderInfoController extends BaseController
{
    @Autowired
    private IOrderInfoService orderInfoService;

    /**
     * 查询订单管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OrderInfo orderInfo)
    {
        startPage();
        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfo);
        return getDataTable(list);
    }

    /**
     * 导出订单管理列表
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:export')")
    @Log(title = "订单管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderInfo orderInfo)
    {
        List<OrderInfo> list = orderInfoService.selectOrderInfoList(orderInfo);
        ExcelUtil<OrderInfo> util = new ExcelUtil<OrderInfo>(OrderInfo.class);
        util.exportExcel(response, list, "订单管理数据");
    }

    /**
     * 获取订单管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(orderInfoService.selectOrderInfoById(id));
    }

    /**
     * 根据订单编号获取信息
     */
    @RequestMapping("/getOrderDataByOrderNum")
    public AjaxResult getOrderDataByOrderNum(OrderInfo orderInfo){
        return success(orderInfoService.getOrderDataByOrderNum(orderInfo));
    }

    /**
     * 新增订单管理
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:add')")
    @Log(title = "订单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.insertOrderInfo(orderInfo));
    }

    /**
     * 修改订单管理
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:edit')")
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.updateOrderInfo(orderInfo));
    }



    /**
     * 删除订单管理
     */
    @PreAuthorize("@ss.hasPermi('payment:payment:remove')")
    @Log(title = "订单管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(orderInfoService.deleteOrderInfoByIds(ids));
    }

    /**
     * 修改订单管理
     */
    @Log(title = "订单管理", businessType = BusinessType.UPDATE)
    @PutMapping("/accept/{id}")
    public AjaxResult edit(@PathVariable Long id)
    {
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setId(id);
        orderInfo.setUserId(SecurityUtils.getUserId());
        return toAjax(orderInfoService.updateOrderInfo(orderInfo));
    }

    /**
     * 更新订单
     */
    @Log(title = "更新订单", businessType = BusinessType.UPDATE)
    @RequestMapping("/updateOrder")
    public AjaxResult updateOrder(@RequestBody OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.updateOrder(orderInfo));
    }


}
